Test Series - java script

Test Number 18/92

Q: The let keyword cannot be used ___________
A. as a substitute of var
B. as a block statement to define new variables
C. to define variables that are scoped to a single expression
D. in a else if loop, as a substitute for var
Solution: The let keyword can be used in four ways :
as a variable declaration like var;
in a for or for/in loop, as a substitute for var;
as a block statement, to define new variables and explicitly delimit their scope; and
to define variables that are scoped to a single expression.
Q: The main difference between the variables declared with var and with let is __________
A. var is confined to a particular function but let is not
B. let is confined to a particular function but var is not
C. var defines values based on conditions but let does not
D. let doesn’t let you change the value of the variable
Solution: Variables declared with var have global scope whereas variable declared with let have block scope. Variables declared with let are defined only within the closest enclosing block (and any blocks nested within it, of course).
Q: What would be the result or type of error if p is not defined in the following JavaScript code snippet?

console.log(p)
A. Zero
B. Null
C. Reference Error
D. Value not found Error
Solution: Console.log() is a predefined function in javascript which is used to print data or message on the console. If the argument of the console.log is not defined it will give a reference error.
Q: What will be the output of the following JavaScript code?

let x=x+1;
console.log(x);
A. 0
B. Null
C. Reference error
D. NaN
Solution: x has not been defined with any value hence the value of x+1 will be Nan. Therefore the console.log function will print NaN.
Q: What will be the output of the following JavaScript code?

[x,y]=[y,x];
A. Throws exception
B. Swap the value of the two variables
C. Flashes an error
D. Creates a new reference object
Solution: The above code snippet will flash an error message. This is due to the fact that the variables x and y are not defined.
Q: Which looping statement allows XML tags to appear in JavaScript programs and adds API for operating on XML data?
A. for loop
B. while loop
C. for/each loop
D. do while loop
Solution: The for/each loop is a new looping statement standardized by E4X. E4X (ECMAScript for XML) is a language extension that allows XML tags to appear literally in JavaScript programs and adds syntax and API for operating on XML data.
Q: Which exception does the Iterators throw from their next() method when there are no more values to iterate, that work on finite collections?
A. Exit Iteration
B. Abort Iteration
C. Abort
D. Stop Iteration
Solution: Iterators that work on finite collections throw Stop Iteration from their next() method when there are no more values to iterate. Stop Iteration is a property of the global object in JavaScript 1.7. Its value is an ordinary object (with no properties of its own) that is reserved for this special purpose of terminating iterations. Note, in particular,that Stop Iteration is not a constructor function like TypeError() or RangeError().
Q: Which method of the iterable object returns an iterator object for the collection?
A. iterator()
B. _iterator_()
C. _iteration_()
D. _return_iterator_()
Solution: An iterable object represents a collection of values that can be iterated. An iterable object must define a method named __iterator__() (with two underscores at the start and end of the name) which returns an iterator object for the collection.
Q: What will be the output of the following JavaScript code?

A. 5.56789e+0
B. 5.57e+0
C. 5.568e+0
D. Error
Solution: The toExponential() method converts a number into an exponential notation. It displays the number of digit according to the input passed to it.
Q: What will be the output of the following JavaScript code?

A. True
B. False
C. Error
D. Undefiend
Solution: NEGATIVE_INFINITY is a static property of the JavaScript Number object. Using x.NEGATIVE_INFINITY, where x is a number or a Number object, will return undefined.

You Have Score    /10